﻿function readSetting( settingName, defaultValue )
{
	var val = System.Gadget.Settings.read( settingName );
    if ( val != "" ) 
	{
		return val
	}
    return defaultValue
}   

function readSettings() 
{	  
	username = readSetting("username", "admin");
	password = readSetting("password", "admin");
	url = readSetting("url", "192.168.2.80:9091");	        
	refresh = readSetting("refresh", 250);
}


function bytesToSize(bytes) {
    var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
    if (bytes == 0) return '0.0 B';
    var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
    return ((i == 0) ? (bytes / Math.pow(1024, i)) : (bytes / Math.pow(1024, i)).toFixed(1)) + ' ' + sizes[i];
};

function bytesToSpeed(bytes) {
    return bytesToSize(bytes) + '/s';
}
